home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / sun / volume2 / sunplot < prev    next >
Encoding:
Internet Message Format  |  1990-02-04  |  34.7 KB

  1. Subject:  v02i009:  Sunplot - a UNIX plot backend for sunview
  2. Newsgroups: comp.sources.sun
  3. Approved: mcgrew@aramis.rutgers.edu
  4.  
  5. Submitted-by: sjoerd@piring.cwi.nl (Sjoerd Mullender)
  6. Posting-number: Volume 2, Issue 9
  7. Archive-name: sunplot
  8.  
  9.  
  10. The subject says it all, really.
  11.  
  12. Sjoerd Mullender        e-mail: sjoerd@cwi.nl
  13. Centre for Mathematics and Computer Science, Amsterdam
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 1 (of 1)."
  22. # Contents:  MANIFEST Makefile README sunplot.1 sunplot.c sunplot.icon
  23. # Wrapped by sjoerd@piring.cwi.nl on Fri Dec  8 10:58:57 1989
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  27. else
  28. echo shar: Extracting \"'MANIFEST'\" \(358 characters\)
  29. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  30. X   File Name        Archive #    Description
  31. X-----------------------------------------------------------
  32. X MANIFEST                   1    This shipping list
  33. X Makefile                   1    Guess
  34. X README                     1    Read this for instructions
  35. X sunplot.1                  1    The manual
  36. X sunplot.c                  1    The source
  37. X sunplot.icon               1    An icon
  38. END_OF_FILE
  39. if test 358 -ne `wc -c <'MANIFEST'`; then
  40.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  41. fi
  42. # end of 'MANIFEST'
  43. fi
  44. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  45.   echo shar: Will not clobber existing file \"'Makefile'\"
  46. else
  47. echo shar: Extracting \"'Makefile'\" \(364 characters\)
  48. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  49. X# The names of the installed binary and manual page.
  50. X# Feel free to change.
  51. XBINARY    = /usr/local/sunplot
  52. XMANUAL    = /usr/man/manl/sunplot.l
  53. X
  54. XCFLAGS    = -O
  55. X
  56. Xsunplot:    sunplot.o
  57. X        $(CC) -o sunplot sunplot.o -lsuntool -lsunwindow -lpixrect
  58. X
  59. Xinstall:    sunplot
  60. X        cp sunplot $(BINARY)
  61. X        cp sunplot.1 $(MANUAL)
  62. X
  63. Xclean:
  64. X        rm -f sunplot *.o core make.out
  65. X
  66. Xsunplot.o:    sunplot.icon
  67. END_OF_FILE
  68. if test 364 -ne `wc -c <'Makefile'`; then
  69.     echo shar: \"'Makefile'\" unpacked with wrong size!
  70. fi
  71. # end of 'Makefile'
  72. fi
  73. if test -f 'README' -a "${1}" != "-c" ; then 
  74.   echo shar: Will not clobber existing file \"'README'\"
  75. else
  76. echo shar: Extracting \"'README'\" \(616 characters\)
  77. sed "s/^X//" >'README' <<'END_OF_FILE'
  78. XThis program was written on a Sun 3/50 running SunOS 3.2.
  79. XIt also compiles and runs on a Sun 3/50 running SunOS 3.5 and a
  80. XSPARCstation 1 running SunOS 4.0.3c.
  81. X
  82. XTo make simply type ``make.''
  83. XTo install, check the Makefile to see if all the names are correct.  Then
  84. Xtype ``make install.''
  85. X
  86. XIf you find any bugs or if you have any suggestions or improvements, please
  87. Xdrop me a note at the address below.
  88. X
  89. XYou might try the command
  90. X    echo 0 0 1 1 2 4 3 9 4 16 | spline | graph | sunplot
  91. Xafter which a window pops up.
  92. X
  93. XSjoerd Mullender
  94. XCentre for Mathematics & Computer Science
  95. XAmsterdam
  96. XNetherlands
  97. X
  98. XEmail: sjoerd@cwi.nl
  99. END_OF_FILE
  100. if test 616 -ne `wc -c <'README'`; then
  101.     echo shar: \"'README'\" unpacked with wrong size!
  102. fi
  103. # end of 'README'
  104. fi
  105. if test -f 'sunplot.1' -a "${1}" != "-c" ; then 
  106.   echo shar: Will not clobber existing file \"'sunplot.1'\"
  107. else
  108. echo shar: Extracting \"'sunplot.1'\" \(5037 characters\)
  109. sed "s/^X//" >'sunplot.1' <<'END_OF_FILE'
  110. X.TH SUNPLOT 1
  111. X.SH NAME
  112. Xsunplot \- plotter backend for Sun workstation
  113. X.SH SYNOPSIS
  114. X.B sunplot
  115. X[
  116. X.B \-c
  117. X.I canvas_size
  118. X] [
  119. X.B \-h
  120. X.I horizontal_size
  121. X] [
  122. X.B \-v
  123. X.I vertical_size
  124. X] [
  125. X.B \-f
  126. X.I font_name
  127. X] [
  128. X.B \-r
  129. X] [
  130. X.B \-x
  131. X] [
  132. X.B \-y
  133. X] [
  134. X.B \-l
  135. X] [
  136. X.B \-s
  137. X] [
  138. X.B \-R
  139. X]
  140. X.SH DESCRIPTION
  141. X.I Sunplot
  142. Xreads UNIX plotter code (see
  143. X.IR plot (5))
  144. Xfrom standard input and displays it in a Sun window.
  145. XThe window consists of two subwindows.
  146. XAt the top is a control panel with a number of buttons and below it is
  147. Xa window with a canvas on which
  148. X.I sunplot
  149. Xdraws and a horizontal and a vertical scrollbar with which you can select
  150. Xwhich part of the canvas you want to see in the window.
  151. XThe buttons in the control panel have the following functions:
  152. X.TP
  153. X.B "Next Page"
  154. XDraw the next page.
  155. XPages are separated by an
  156. X.B e
  157. X(the
  158. X.I erase
  159. Xfunction in the
  160. X.IR plot (3X)
  161. Xlibrary).
  162. XThis button is not displayed while
  163. X.I sunplot
  164. Xis still reading a page or when the end of the input has been reached.
  165. X.TP
  166. X.B Redraw
  167. XRedraw the current page.
  168. X.TP
  169. X.B Zoom
  170. XZoom the current page.
  171. X.I Sunplot
  172. Xfinds the most extreme x- and y-coordinates in the current page and uses
  173. Xthose values in stead of the values given by the
  174. X.B s
  175. Xcommand (the
  176. X.I space
  177. Xfunction) for scaling.
  178. X.TP
  179. X.B Options
  180. X.I Sunplot
  181. Xdisplays a window where you can set certain options.
  182. XSee the description below.
  183. X.TP
  184. X.B Dump
  185. X.I Sunplot
  186. Xdisplays a window with four items.
  187. XYou should type a file name after the string
  188. X.B Dump to file:
  189. Xand then press the
  190. X.B Dump
  191. Xbutton.
  192. X.I Sunplot
  193. Xwill then dump the plot into the named file in the format chosen with the
  194. X.B Dump format
  195. Xitem.
  196. XThe dump can be in
  197. X.IR rasterfile (5),
  198. X.IR icon ,
  199. Xor
  200. X.I UNIX
  201. X.IR plot (5)
  202. Xformat.
  203. XIf the file name is empty,
  204. X.I sunplot
  205. Xwill do nothing.
  206. XThe dump subwindow will continue to be displayed until the
  207. X.B Done
  208. Xbutton is selected.
  209. X.TP
  210. X.B "Fit Screen"
  211. XResize the window so that the canvas fits.
  212. X.TP
  213. X.B Quit
  214. XExit
  215. X.I sunplot
  216. Xwithout asking for user confirmation.
  217. X.SH OPTIONS
  218. XWhen the
  219. X.B Options
  220. Xbutton is pressed
  221. X.I sunplot
  222. Xwill display a window with the following items.
  223. X.TP
  224. X.B Done
  225. XDone setting options.
  226. XThe window disappears and the page is redrawn with the new settings.
  227. X.TP
  228. X.B Apply
  229. XApply the selected options.
  230. X.I Sunplot
  231. Xwill automatically do a redraw of the page with the new settings.
  232. X.TP
  233. X.B Rotate
  234. XRotate the plot by 90 degrees counter-clockwise.
  235. X.TP
  236. X.B "X Mirror"
  237. XMirror the plot in the x-axis.
  238. X.TP
  239. X.B "Y Mirror"
  240. XMirror the plot in the y-axis.
  241. X.TP
  242. X.B Label
  243. XIf on, display labels.
  244. X.TP
  245. X.B Square
  246. XIf on, the canvas is square, otherwise you can set the horizontal and vertical
  247. Xsizes of the canvas separately.
  248. X.TP
  249. X.B Reverse
  250. XDisplay the canvas in reverse video.
  251. X.TP
  252. X.B "Font name"
  253. XThe name of the font to be used for the labels.
  254. XIf the name is not absolute it is taken to be relative to the system's fonts
  255. Xdirectory /usr/lib/fonts/fixedwidthfonts.
  256. XIf no name is given or the named file does not contain a font, the default
  257. Xfont is used.
  258. X.TP
  259. X.B "Canvas size"
  260. XThe size of the canvas.
  261. XThe size of the canvas is measured in pixels.
  262. XThis is only displayed when the
  263. X.B Square
  264. Xtoggle is on.
  265. X.TP
  266. X.B "Horizontal size"
  267. XThe horizontal size of the canvas.
  268. XThis is only displayed when the
  269. X.B Square
  270. Xtoggle is off.
  271. X.TP
  272. X.B "Vertical size"
  273. XThe vertical size of the canvas.
  274. XThis is only displayed when the
  275. X.B Square
  276. Xtoggle is off.
  277. X.PP
  278. XThe following command line options are recognized.
  279. X.IP "\f3\-c\fP \f2canvas_size\fP"
  280. XSet the canvas size.
  281. X.I Canvas_size
  282. Xmust be between 64 and 2048.
  283. XThis also switches on the
  284. X.B Square
  285. Xtoggle.
  286. X.IP "\f3\-h\fP \f2horizontal_size\fP"
  287. XSet the horizontal size.
  288. X.I Horizontal_size
  289. Xmust be between 64 and 2048.
  290. XThis also switches off the
  291. X.B Square
  292. Xtoggle.
  293. X.IP "\f3\-v\fP \f2vertical_size\fP"
  294. XSet the vertical size.
  295. X.I Vertical_size
  296. Xmust be between 64 and 2048.
  297. XThis also switches off the
  298. X.B Square
  299. Xtoggle.
  300. X.IP "\f3\-f\fP \f2font_name\fP"
  301. XSet the font to be used for labels.
  302. XThis is independent from the font that is used for the text in the control
  303. Xpanel and the options and dump windows.
  304. XA name not starting with ``/'' is taken to be relative to the system's font
  305. Xdirectory /usr/lib/fonts/fixedwidthfonts.
  306. X.IP \f3\-r\fP
  307. XRotate the plot by 90 degrees counter-clockwise.
  308. X.IP \f3\-x\fP
  309. XMirror the plot in the x-axis.
  310. X.IP \f3\-y\fP
  311. XMirror the plot in the y-axis.
  312. X.IP \f3\-l\fP
  313. XToggle labeling.
  314. X.IP \f3\-s\fP
  315. XToggle square mode.
  316. X.IP \f3\-R\fP
  317. XDisplay in reverse video (white on black).
  318. X.PP
  319. XThe
  320. X.BR \-r ,
  321. X.B \-x
  322. Xand
  323. X.B \-y
  324. Xoptions are evaluated left to right and can be repeated to get cumulative
  325. Xeffect.
  326. X.I Sunplot
  327. Xalso recognizes the generic tool arguments; see
  328. X.IR suntools (1)
  329. Xfor a list of these arguments.
  330. X.PP
  331. XThe defaults are: labels printed, square canvas, canvas size is 512
  332. Xby 512 pixels, the point
  333. X.I "(0,\ 0)"
  334. Xis in the lower left-hand corner.
  335. X.SH BUGS
  336. XThe
  337. X.I linemod
  338. Xfunction is not implemented.
  339. X.PP
  340. XThe
  341. X.B zoom
  342. Xcommand doesn't take the height and width of labels into account.
  343. X.SH "SEE ALSO"
  344. X.IR plot (3X),
  345. X.IR plot (5),
  346. Xand
  347. X.IR rasterfile (5).
  348. X.SH AUTHOR
  349. XSjoerd Mullender, Free University, Amsterdam <sjoerd@cs.vu.nl>
  350. END_OF_FILE
  351. if test 5037 -ne `wc -c <'sunplot.1'`; then
  352.     echo shar: \"'sunplot.1'\" unpacked with wrong size!
  353. fi
  354. # end of 'sunplot.1'
  355. fi
  356. if test -f 'sunplot.c' -a "${1}" != "-c" ; then 
  357.   echo shar: Will not clobber existing file \"'sunplot.c'\"
  358. else
  359. echo shar: Extracting \"'sunplot.c'\" \(22427 characters\)
  360. sed "s/^X//" >'sunplot.c' <<'END_OF_FILE'
  361. X/*
  362. X * Sunplot - plotter backend for Sun workstation
  363. X *
  364. X * Copyright (c) 1987 by Sjoerd Mullender, Vrije Universiteit, Amsterdam.
  365. X *
  366. X * This program may be redistributed without fee as long as this copyright
  367. X * notice is in tact.
  368. X * Any commercial use is strictly prohibited.
  369. X */
  370. X
  371. X#ifndef lint
  372. Xstatic char rcsid[] = "$Header: /tmp_mnt/tuintje/ufs1/cl/sjoerd/src/sunplot/RCS/sunplot.c,v 1.5 89/12/08 10:53:15 sjoerd Exp $";
  373. X#endif
  374. X
  375. X#include <stdio.h>
  376. X#include <suntool/sunview.h>
  377. X#include <suntool/scrollbar.h>
  378. X#include <suntool/panel.h>
  379. X#include <suntool/canvas.h>
  380. X
  381. X/*
  382. X * Configurable definitions
  383. X */
  384. X#define INIT_CANVAS_SIZE    512
  385. X#define DEFAULT_SPACE        4096
  386. X#define MAX_NAME_LENGTH        128
  387. X
  388. X/*
  389. X * Unconfigurable definitions
  390. X */
  391. X#define BIG            0x7FFFFFFF
  392. X
  393. X#define FORMAT_RASTER        0
  394. X#define FORMAT_ICON        1
  395. X#define FORMAT_PLOT        2
  396. X
  397. X#define LABEL            0
  398. X#define SQUARE            1
  399. X#define REVERSE            2
  400. X
  401. Xint client_object;        /* used for notifier */
  402. Xint *me = &client_object;    /* idem */
  403. X
  404. Xint curx, cury;            /* current position on plot */
  405. Xint lox, loy, hix = DEFAULT_SPACE, hiy = DEFAULT_SPACE;    /* current space */
  406. Xint slox, shix, sloy, shiy;    /* saved space settings for zooming */
  407. Xint minx, maxx, miny, maxy;    /* minimum and maximum values encountered */
  408. Xint hor_size, ver_size;        /* canvas size */
  409. Xint turned, xmirror, ymirror;    /* orientation of plot */
  410. Xint zooming;
  411. Xint make_label = TRUE;        /* print labels */
  412. Xint square = TRUE;        /* canvas is square */
  413. Xint reverse = FALSE;        /* reverse video */
  414. Xint dirty;
  415. XFrame frame, dump_frame, options_frame;
  416. XPanel panel, dump_panel, options_panel;
  417. XPanel_item next_page_item;
  418. XPanel_item hor_size_item, ver_size_item, toggle_item, font_item;
  419. XPanel_item dump_format, dump_file_item;
  420. XCanvas canvas;
  421. XPixwin *pw;
  422. XPixfont *font;
  423. Xchar font_name[MAX_NAME_LENGTH];
  424. Xchar font_dir[] = "/usr/lib/fonts/fixedwidthfonts/";
  425. XPr_texture texture;
  426. XPr_brush brush = {1};
  427. X
  428. Xshort sunplot_icon_image[] = {
  429. X#include "sunplot.icon"
  430. X};
  431. Xmpr_static(sunplot_icon, 64, 64, 1, sunplot_icon_image);
  432. X
  433. Xchar *malloc(), *realloc();
  434. X
  435. X/*
  436. X *  input module
  437. X */
  438. X
  439. Xstatic char *plotcommands, *plptr;
  440. Xstatic int plotlength;
  441. Xstatic int maxplotlength;
  442. Xstatic int eof_seen;
  443. X
  444. Xgetchr()
  445. X{
  446. X    register c;
  447. X
  448. X    if (plptr < plotcommands + plotlength)
  449. X        return *plptr++ & 0xFF;
  450. X    if (eof_seen || (c = getchar()) == EOF) {
  451. X        eof_seen = 1;
  452. X        return EOF;
  453. X    }
  454. X    if (plotlength >= maxplotlength) {
  455. X        plotcommands = realloc(plotcommands, maxplotlength *= 2);
  456. X        plptr = plotcommands + plotlength;
  457. X    }
  458. X    *plptr++ = c;
  459. X    plotlength++;
  460. X    return c;
  461. X}
  462. X
  463. Xgetint()
  464. X{
  465. X    register n;
  466. X
  467. X    n = getchr();
  468. X    n = n | getchr() << 8;
  469. X    if (n & 0x8000)            /* sign extend */
  470. X        n |= ~0x7FFF;
  471. X    return n;
  472. X}
  473. X
  474. Xchar *getstr()
  475. X{
  476. X    register i = plptr - plotcommands;
  477. X    register c;
  478. X
  479. X    while ((c = getchr()) != EOF && c != '\0' && c != '\n')
  480. X        ;
  481. X    plptr[-1] = 0;
  482. X    return plotcommands + i;
  483. X}
  484. X
  485. X/*
  486. X * plot module
  487. X */
  488. X
  489. X#define point(x,y)    pw_put(pw, plotx(x, y), ploty(x, y), !reverse)
  490. X
  491. X#if 0
  492. X#define line(x0,y0,x1,y1)    pw_vector(pw,plotx(x0,y0),ploty(x0,y0),plotx(x1,y1),ploty(x1,y1),PIX_SRC,!reverse)
  493. X#else
  494. X#define line(x0,y0,x1,y1)    pw_line(pw,plotx(x0,y0),ploty(x0,y0),plotx(x1,y1),ploty(x1,y1),&brush,&texture,reverse?PIX_CLR:PIX_SET)
  495. X#endif
  496. X
  497. X#define convx(x,s)    (((x) - lox) * (s) / (hix - lox))
  498. X#define convy(y,s)    (((y) - loy) * (s) / (hiy - loy))
  499. X
  500. Xinitplot()
  501. X{
  502. X    plptr = plotcommands = malloc(maxplotlength = 1024);
  503. X    plotlength = 0;
  504. X}
  505. X
  506. Xplotx(x, y)
  507. X{
  508. X    register a;
  509. X
  510. X    switch (turned) {
  511. X    case 0: a = convx(x, hor_size); break;
  512. X    case 1: a = hor_size - 1 - convy(y, hor_size); break;
  513. X    case 2: a = hor_size - 1 - convx(x, hor_size); break;
  514. X    case 3: a = convy(y, hor_size); break;
  515. X    }
  516. X    return xmirror ? hor_size - 1 - a : a;
  517. X}
  518. X
  519. Xploty(x, y)
  520. X{
  521. X    register a;
  522. X
  523. X    switch (turned) {
  524. X    case 0: a = ver_size - 1 - convy(y, ver_size); break;
  525. X    case 1: a = ver_size - 1 - convx(x, ver_size); break;
  526. X    case 2: a = convy(y, ver_size); break;
  527. X    case 3: a = convx(x, ver_size); break;
  528. X    }
  529. X    a = ymirror ? ver_size - 1 - a : a;
  530. X    return zooming ? a+1 : a;
  531. X}
  532. X
  533. Xlabel(s)
  534. Xchar *s;
  535. X{
  536. X    struct pr_size pr_size;
  537. X
  538. X    if (!make_label)
  539. X        return 0;
  540. X    pw_text(pw, plotx(curx, cury), ploty(curx, cury), reverse ? PIX_NOT(PIX_SRC)&PIX_DST : PIX_SRC|PIX_DST, font, s);
  541. X    pr_size = pf_textwidth(strlen(s), font, s);
  542. X    return pr_size.x * (hix - lox) / hor_size;
  543. X}
  544. X
  545. Xlinemod(s)
  546. Xchar *s;
  547. X{
  548. X    static short dotted[] = {1,5,0};
  549. X    static short solid[] = {1,0};
  550. X    static short longdashed[] = {10,6,0};
  551. X    static short shortdashed[] = {5,3,0};
  552. X    static short dotdashed[] = {7,3,1,3,0};
  553. X
  554. X    if (strcmp(s, "dotted") == 0) {
  555. X        texture.pattern = dotted;
  556. X    } else if (strcmp(s, "solid") == 0) {
  557. X        texture.pattern = solid;
  558. X    } else if (strcmp(s, "longdashed") == 0) {
  559. X        texture.pattern = longdashed;
  560. X    } else if (strcmp(s, "shortdashed") == 0) {
  561. X        texture.pattern = shortdashed;
  562. X    } else if (strcmp(s, "dotdashed") == 0) {
  563. X        texture.pattern = dotdashed;
  564. X    }
  565. X}
  566. X
  567. Xisqrt(n)
  568. X{
  569. X    int a, b, c;
  570. X
  571. X    a = n;
  572. X    b = n;
  573. X    if (n > 1) {
  574. X        while (a > 0) {
  575. X            a = a >> 2;
  576. X            b = b >> 1;
  577. X        }
  578. X        do {
  579. X            a = b;
  580. X            c = n / b;
  581. X            b = (c + a) >> 1;
  582. X        } while ((a - c) < -1 || (a - c) > 1);
  583. X    }
  584. X    return b;
  585. X}
  586. X
  587. Xstatic setcir(x, y, a1, b1, c1, a2, b2, c2)
  588. X{
  589. X    if (a1 * y - b1 * x >= c1 && a2 * y - b2 * x <= c2)
  590. X        point(x, y);
  591. X}
  592. X
  593. Xarc(x, y, x1, y1, x2, y2)
  594. X{
  595. X    register a1 = x1 - x, b1 = y1 - y, a2 = x2 - x, b2 = y2 - y;
  596. X    register c1 = a1 * y - b1 * x, c2 = a2 * y - b2 * x;
  597. X    register r2 = a1 * a1 + b1 * b1;
  598. X    register i, di, sqrt, dx, dy;
  599. X
  600. X    dx = (hix - lox) / hor_size;
  601. X    dy = (hiy - loy) / ver_size;
  602. X    di = dx < dy ? dx : dy;
  603. X    if (di <= 0)
  604. X        di = 1;
  605. X    for (i = isqrt(r2 >> 1); i >= 0; i -= di) {
  606. X        sqrt = isqrt(r2 - i * i);
  607. X        setcir(x + i, y + sqrt, a1, b1, c1, a2, b2, c2);
  608. X        setcir(x + i, y - sqrt, a1, b1, c1, a2, b2, c2);
  609. X        setcir(x - i, y + sqrt, a1, b1, c1, a2, b2, c2);
  610. X        setcir(x - i, y - sqrt, a1, b1, c1, a2, b2, c2);
  611. X        setcir(x + sqrt, y + i, a1, b1, c1, a2, b2, c2);
  612. X        setcir(x + sqrt, y - i, a1, b1, c1, a2, b2, c2);
  613. X        setcir(x - sqrt, y + i, a1, b1, c1, a2, b2, c2);
  614. X        setcir(x - sqrt, y - i, a1, b1, c1, a2, b2, c2);
  615. X    }
  616. X}
  617. X
  618. Xcircle(x, y, r)
  619. X{
  620. X    arc(x, y, x + r, y, x - r, y);
  621. X    arc(x, y, x - r, y, x + r, y);
  622. X}
  623. X
  624. XNotify_value input_reader(me, fd)
  625. Xint *me;
  626. Xint fd;
  627. X{
  628. X    int newx, newy, x, y, r;
  629. X    register char *p;
  630. X
  631. X    do {
  632. X        switch (getchr()) {
  633. X        case 'm':                /* move */
  634. X            dirty = 1;
  635. X            curx = getint();
  636. X            cury = getint();
  637. X            if (curx < minx) minx = curx;
  638. X            if (curx > maxx) maxx = curx;
  639. X            if (cury < miny) miny = cury;
  640. X            if (cury > maxy) maxy = cury;
  641. X            break;
  642. X        case 'n':                /* cont */
  643. X            dirty = 1;
  644. X            newx = getint();
  645. X            newy = getint();
  646. X            line(curx, cury, newx, newy);
  647. X            curx = newx;
  648. X            cury = newy;
  649. X            if (curx < minx) minx = curx;
  650. X            if (curx > maxx) maxx = curx;
  651. X            if (cury < miny) miny = cury;
  652. X            if (cury > maxy) maxy = cury;
  653. X            break;
  654. X        case 'p':                /* point */
  655. X            dirty = 1;
  656. X            curx = getint();
  657. X            cury = getint();
  658. X            point(curx, cury);
  659. X            if (curx < minx) minx = curx;
  660. X            if (curx > maxx) maxx = curx;
  661. X            if (cury < miny) miny = cury;
  662. X            if (cury > maxy) maxy = cury;
  663. X            break;
  664. X        case 'l':                /* line */
  665. X            dirty = 1;
  666. X            newx = getint();
  667. X            newy = getint();
  668. X            curx = getint();
  669. X            cury = getint();
  670. X            line(newx, newy, curx, cury);
  671. X            if (newx < minx) minx = newx;
  672. X            if (newx > maxx) maxx = newx;
  673. X            if (newy < miny) miny = newy;
  674. X            if (newy > maxy) maxy = newy;
  675. X            if (curx < minx) minx = curx;
  676. X            if (curx > maxx) maxx = curx;
  677. X            if (cury < miny) miny = cury;
  678. X            if (cury > maxy) maxy = cury;
  679. X            break;
  680. X        case 't':                /* label */
  681. X            dirty = 1;
  682. X            p = getstr();
  683. X            curx += label(p);
  684. X            plptr[-1] = '\n';
  685. X            if (curx < minx) minx = curx;
  686. X            if (curx > maxx) maxx = curx;
  687. X            break;
  688. X        case 'a':                /* arc */
  689. X            dirty = 1;
  690. X            x = getint();
  691. X            y = getint();
  692. X            newx = getint();
  693. X            newy = getint();
  694. X            curx = getint();
  695. X            cury = getint();
  696. X            arc(x, y, newx, newy, curx, cury);
  697. X            if (x < minx) minx = x;
  698. X            if (x > maxx) maxx = x;
  699. X            if (y < miny) miny = y;
  700. X            if (y > maxy) maxy = y;
  701. X            if (newx < minx) minx = newx;
  702. X            if (newx > maxx) maxx = newx;
  703. X            if (newy < miny) miny = newy;
  704. X            if (newy > maxy) maxy = newy;
  705. X            if (curx < minx) minx = curx;
  706. X            if (curx > maxx) maxx = curx;
  707. X            if (cury < miny) miny = cury;
  708. X            if (cury > maxy) maxy = cury;
  709. X            break;
  710. X        case 'c':                /* circle */
  711. X            dirty = 1;
  712. X            curx = getint();
  713. X            cury = getint();
  714. X            r = getint();
  715. X            circle(curx, cury, r);
  716. X            if (curx - r < minx) minx = curx - r;
  717. X            if (curx + r > maxx) maxx = curx + r;
  718. X            if (cury - r < miny) miny = cury - r;
  719. X            if (cury + r > maxy) maxy = cury + r;
  720. X            break;
  721. X        case 'e':                /* erase */
  722. X            if (!dirty)
  723. X                break;
  724. X            panel_set(next_page_item, PANEL_SHOW_ITEM, TRUE, 0);
  725. X            /* fall through */
  726. X        case EOF:
  727. X            notify_set_input_func(me, NOTIFY_FUNC_NULL, fd);
  728. X            if (zooming) {
  729. X                lox = slox;
  730. X                hix = shix;
  731. X                loy = sloy;
  732. X                hiy = shiy;
  733. X                zooming = 0;
  734. X            }
  735. X            return NOTIFY_DONE;
  736. X        case 'f':                /* linemod */
  737. X            dirty = 1;
  738. X            p = getstr();
  739. X            linemod(p);
  740. X            plptr[-1] = '\n';
  741. X            break;
  742. X        case 's':                /* space */
  743. X            if (zooming) {
  744. X                slox = getint();
  745. X                sloy = getint();
  746. X                shix = getint();
  747. X                shiy = getint();
  748. X            } else {
  749. X                lox = getint();
  750. X                loy = getint();
  751. X                hix = getint();
  752. X                hiy = getint();
  753. X            }
  754. X            break;
  755. X        }
  756. X    } while (plptr < plotcommands + plotlength || stdin->_cnt > 0);
  757. X    return NOTIFY_DONE;
  758. X}
  759. X
  760. X/*
  761. X * button routines
  762. X */
  763. X
  764. Xrestartplot()
  765. X{
  766. X    dirty = 0;
  767. X    minx = BIG;
  768. X    maxx = -BIG;
  769. X    miny = BIG;
  770. X    maxy = -BIG;
  771. X    plptr = plotcommands;
  772. X
  773. X    /* clear the canvas */
  774. X    pw_writebackground(pw, 0, 0, (int) window_get(canvas, CANVAS_WIDTH),
  775. X                (int) window_get(canvas, CANVAS_HEIGHT),
  776. X                reverse ? PIX_SET : PIX_CLR);
  777. X}
  778. X
  779. Xresetplot()
  780. X{
  781. X    restartplot();
  782. X    plotlength = 0;
  783. X}
  784. X
  785. Xvoid redraw()
  786. X{
  787. X    if (zooming) {
  788. X        lox = slox;
  789. X        hix = shix;
  790. X        loy = sloy;
  791. X        hiy = shiy;
  792. X        zooming = 0;
  793. X    }
  794. X    restartplot();
  795. X    input_reader(me, fileno(stdin));
  796. X}
  797. X
  798. Xvoid nextpage()
  799. X{
  800. X    resetplot();
  801. X    panel_set(next_page_item, PANEL_SHOW_ITEM, FALSE, 0);
  802. X    notify_set_input_func(me, input_reader, fileno(stdin));
  803. X    if (stdin->_cnt > 0)
  804. X        input_reader(me, fileno(stdin));
  805. X}
  806. X
  807. Xvoid zoom()
  808. X{
  809. X    int a;
  810. X
  811. X    if (!zooming) {
  812. X        slox = lox;
  813. X        shix = hix;
  814. X        sloy = loy;
  815. X        shiy = hiy;
  816. X        zooming = 1;
  817. X    }
  818. X    if (maxx == minx) {
  819. X        maxx++;
  820. X        minx--;
  821. X    }
  822. X    if (maxy == miny) {
  823. X        maxy++;
  824. X        miny--;
  825. X    }
  826. X    if ((a = (maxx-minx) * (shiy-sloy) / (shix-slox)) >= maxy-miny) {
  827. X        loy = miny - (a - maxy + miny) / 2;
  828. X        hiy = loy + a;
  829. X        lox = minx;
  830. X        hix = maxx;
  831. X    } else {
  832. X        a = (maxy - miny) * (shix - slox) / (shiy - sloy);
  833. X        lox = minx - (a - maxx + minx) / 2;
  834. X        hix = lox + a;
  835. X        loy = miny;
  836. X        hiy = maxy;
  837. X    }
  838. X    hix++;
  839. X    hiy++;
  840. X    restartplot();
  841. X    input_reader(me, fileno(stdin));
  842. X}
  843. X
  844. Xvoid quit()
  845. X{
  846. X    /* don't ask for confirmation */
  847. X    if (font)
  848. X        pf_close(font);
  849. X    window_set(frame, FRAME_NO_CONFIRM, TRUE, 0);
  850. X    window_destroy(frame);
  851. X}
  852. X
  853. Xvoid turn()
  854. X{
  855. X    int tmp;
  856. X
  857. X    turned = (turned + 1) & 3;
  858. X    tmp = xmirror;
  859. X    xmirror = ymirror;
  860. X    ymirror = tmp;
  861. X}
  862. X
  863. Xvoid mirrorx()
  864. X{
  865. X    xmirror ^= 1;
  866. X}
  867. X
  868. Xvoid mirrory()
  869. X{
  870. X    ymirror ^= 1;
  871. X}
  872. X
  873. Xvoid canvas_fit()
  874. X{
  875. X    register int w, h;
  876. X    
  877. X    w = (int) window_get(canvas, WIN_WIDTH) - (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_VERTICAL_SCROLLBAR), SCROLL_THICKNESS);
  878. X    h = (int) window_get(canvas, WIN_HEIGHT) - (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_HORIZONTAL_SCROLLBAR), SCROLL_THICKNESS);
  879. X    if ((int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, SQUARE)) {
  880. X        if (w < h)
  881. X            h = w;
  882. X        else
  883. X            w = h;
  884. X    }
  885. X    panel_set(hor_size_item, PANEL_VALUE, w, 0);
  886. X    panel_set(ver_size_item, PANEL_VALUE, h, 0);
  887. X}
  888. X
  889. X/*
  890. X * initialization
  891. X */
  892. X
  893. Xvoid toggle_proc()
  894. X{
  895. X    if ((int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, SQUARE)) {
  896. X        panel_set(ver_size_item,
  897. X            PANEL_SHOW_ITEM,    FALSE,
  898. X            0);
  899. X        panel_set(hor_size_item,
  900. X            PANEL_LABEL_STRING,    "Canvas size:     ",
  901. X            0);
  902. X    } else {
  903. X        panel_set(ver_size_item,
  904. X            PANEL_SHOW_ITEM,    TRUE,
  905. X            0);
  906. X        panel_set(hor_size_item,
  907. X            PANEL_LABEL_STRING,    "Horizontal size: ",
  908. X            0);
  909. X    }
  910. X}
  911. X
  912. Xvoid options()
  913. X{
  914. X    window_set(options_frame, WIN_SHOW, TRUE, 0);
  915. X}
  916. X
  917. Xvoid apply_options()
  918. X{
  919. X    register int r;
  920. X    char *f;
  921. X    Cursor cursor;
  922. X
  923. X    square = (int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, SQUARE);
  924. X    r = (int) panel_get(hor_size_item, PANEL_VALUE);
  925. X    if (r != hor_size) {
  926. X        window_set(canvas, CANVAS_WIDTH, r, 0);
  927. X        hor_size = r;
  928. X    }
  929. X    if (square)
  930. X        r = hor_size;
  931. X    else
  932. X        r = (int) panel_get(ver_size_item, PANEL_VALUE);
  933. X    if (r != ver_size) {
  934. X        window_set(canvas, CANVAS_HEIGHT, r, 0);
  935. X        ver_size = r;
  936. X    }
  937. X    f = (char *) panel_get_value(font_item);
  938. X    if (f == 0 || *f == 0) {
  939. X        if (font_name[0] != 0) {
  940. X            font_name[0] = 0;
  941. X            if (font)
  942. X                pf_close(font);
  943. X            font = pf_default();
  944. X        }
  945. X    } else {
  946. X        if (font_name[0] == 0 || strcmp(f, font_name) != 0) {
  947. X            strcpy(font_name, f);
  948. X            f = font_name;
  949. X            if (*f != '/') {
  950. X                f = malloc(strlen(font_dir)+strlen(font_name)+1);
  951. X                strcpy(f, font_dir);
  952. X                strcat(f, font_name);
  953. X            }
  954. X            if (font)
  955. X                pf_close(font);
  956. X            font = pf_open(f);
  957. X            if (f != font_name)
  958. X                free(f);
  959. X        }
  960. X    }
  961. X    if (font == 0) {
  962. X        font_name[0] = 0;
  963. X        font = pf_default();
  964. X    }
  965. X    make_label = (int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, LABEL);
  966. X    reverse = (int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, REVERSE);
  967. X    cursor = (Cursor) window_get(canvas, WIN_CURSOR);
  968. X    cursor_set(cursor,
  969. X            CURSOR_OP, reverse ? PIX_SRC^PIX_DST : PIX_SRC|PIX_DST,
  970. X            0);
  971. X    window_set(canvas, WIN_CURSOR, cursor, 0);
  972. X    redraw();
  973. X}
  974. X
  975. Xvoid options_done()
  976. X{
  977. X    window_set(options_frame, WIN_SHOW, FALSE, 0);
  978. X    apply_options();
  979. X}
  980. X
  981. Xvoid dump()
  982. X{
  983. X    window_set(dump_frame, WIN_SHOW, TRUE, 0);
  984. X}
  985. X
  986. Xvoid do_dump()
  987. X{
  988. X    char *file;
  989. X    int width, height;
  990. X    register int x, y;
  991. X    register char *s;
  992. X    register short *p;
  993. X    FILE *f;
  994. X
  995. X    /* we use the fact that the canvas is retained */
  996. X    file = (char *) panel_get_value(dump_file_item);
  997. X    if (file != 0 && *file != 0 && (f = fopen(file, "w")) != 0) {
  998. X        width = (int) window_get(canvas, CANVAS_WIDTH);
  999. X        height = (int) window_get(canvas, CANVAS_HEIGHT);
  1000. X        switch ((int) panel_get_value(dump_format)) {
  1001. X        case FORMAT_RASTER:
  1002. X            pr_dump(pw->pw_prretained, f, (colormap_t *) 0,
  1003. X                            RT_STANDARD, 0);
  1004. X            break;
  1005. X        case FORMAT_ICON:
  1006. X            p = mpr_d(pw->pw_prretained)->md_image;
  1007. X            fprintf(f, "\
  1008. X/* Format_version=1, Width=%d, Height=%d, Depth=1, Valid_bits_per_item=16\n\
  1009. X */\n", (width+15) & ~15, height);
  1010. X            for (y = 0; y < height; y++) {
  1011. X                s = "\t";
  1012. X                for (x = 0; x < width; x += 16) {
  1013. X                    fprintf(f, "%s0x%04x,", s, *p & 0xFFFF);
  1014. X                    p++;
  1015. X                    s = "";
  1016. X                }
  1017. X                fprintf(f, "\n");
  1018. X            }
  1019. X            break;
  1020. X        case FORMAT_PLOT:
  1021. X            fwrite(plotcommands, 1, plotlength, f);
  1022. X            break;
  1023. X        }
  1024. X        fclose(f);
  1025. X    }
  1026. X}
  1027. X
  1028. Xvoid dump_done()
  1029. X{
  1030. X    window_set(dump_frame, WIN_SHOW, FALSE, 0);
  1031. X}
  1032. X
  1033. Xvoid fit_screen()
  1034. X{
  1035. X    register int w, h;
  1036. X    
  1037. X    w = hor_size + (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_VERTICAL_SCROLLBAR), SCROLL_THICKNESS);
  1038. X    h = ver_size + (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_HORIZONTAL_SCROLLBAR), SCROLL_THICKNESS);
  1039. X    window_set(canvas, WIN_WIDTH, w, WIN_HEIGHT, h, 0);
  1040. X    window_set(canvas, CANVAS_WIDTH, hor_size, CANVAS_HEIGHT, ver_size, 0);
  1041. X    window_set(panel, WIN_WIDTH, w, 0);
  1042. X    window_fit(frame);
  1043. X}
  1044. X
  1045. X/*
  1046. X * initialization
  1047. X */
  1048. X
  1049. Xvoid dump_init()
  1050. X{
  1051. X    register Pixrect *pr;
  1052. X
  1053. X    dump_frame = window_create(frame, FRAME,
  1054. X            FRAME_DONE_PROC,    dump_done,
  1055. X            0);
  1056. X    dump_panel = window_create(dump_frame, PANEL, 0);
  1057. X    pr = panel_button_image(dump_panel, "Done", 0, (Pixfont *) 0);
  1058. X    (void) panel_create_item(dump_panel, PANEL_BUTTON,
  1059. X            PANEL_LABEL_IMAGE,    pr,
  1060. X            PANEL_NOTIFY_PROC,    dump_done,
  1061. X            0);
  1062. X    pr = panel_button_image(dump_panel, "Dump", 0, (Pixfont *) 0);
  1063. X    (void) panel_create_item(dump_panel, PANEL_BUTTON,
  1064. X            PANEL_LABEL_IMAGE,    pr,
  1065. X            PANEL_NOTIFY_PROC,    do_dump,
  1066. X            0);
  1067. X    /* order of strings is important (see definitions of FORMAT_*) */
  1068. X    dump_format = panel_create_item(dump_panel, PANEL_CYCLE,
  1069. X            PANEL_LABEL_STRING,    "Dump format:",
  1070. X            PANEL_CHOICE_STRINGS,    "Rasterfile format",
  1071. X                        "Icon format",
  1072. X                        "Plot format",
  1073. X                        (char *) 0,
  1074. X            0);
  1075. X    dump_file_item = panel_create_item(dump_panel, PANEL_TEXT,
  1076. X            PANEL_LABEL_X,        ATTR_COL(0),
  1077. X            PANEL_LABEL_Y,        ATTR_ROW(1),
  1078. X            PANEL_VALUE_DISPLAY_LENGTH, 30,
  1079. X            PANEL_LABEL_STRING,    "Dump to file:",
  1080. X            0);
  1081. X    window_fit(dump_panel);
  1082. X    window_fit(dump_frame);
  1083. X}
  1084. X
  1085. Xvoid options_init()
  1086. X{
  1087. X    register Pixrect *pr;
  1088. X
  1089. X    options_frame = window_create(frame, FRAME,
  1090. X            FRAME_DONE_PROC,    options_done,
  1091. X            0);
  1092. X    options_panel = window_create(options_frame, PANEL, 0);
  1093. X
  1094. X    pr = panel_button_image(options_panel, "Done", 0, (Pixfont *) 0);
  1095. X    (void) panel_create_item(options_panel, PANEL_BUTTON,
  1096. X            PANEL_LABEL_IMAGE,    pr,
  1097. X            PANEL_NOTIFY_PROC,    options_done,
  1098. X            0);
  1099. X    pr = panel_button_image(options_panel, "Apply", 0, (Pixfont *) 0);
  1100. X    (void) panel_create_item(options_panel, PANEL_BUTTON,
  1101. X            PANEL_LABEL_IMAGE,    pr,
  1102. X            PANEL_NOTIFY_PROC,    apply_options,
  1103. X            0);
  1104. X    pr = panel_button_image(options_panel, "Rotate", 0, (Pixfont*) 0);
  1105. X    (void) panel_create_item(options_panel, PANEL_BUTTON,
  1106. X            PANEL_NOTIFY_PROC,    turn,
  1107. X            PANEL_LABEL_IMAGE,    pr,
  1108. X            0);
  1109. X    pr = panel_button_image(options_panel, "X Mirror", 0, (Pixfont*) 0);
  1110. X    (void) panel_create_item(options_panel, PANEL_BUTTON,
  1111. X            PANEL_NOTIFY_PROC,    mirrorx,
  1112. X            PANEL_LABEL_IMAGE,    pr,
  1113. X            0);
  1114. X    pr = panel_button_image(options_panel, "Y Mirror", 0, (Pixfont*) 0);
  1115. X    (void) panel_create_item(options_panel, PANEL_BUTTON,
  1116. X            PANEL_NOTIFY_PROC,    mirrory,
  1117. X            PANEL_LABEL_IMAGE,    pr,
  1118. X            0);
  1119. X    pr = panel_button_image(options_panel, "Fit Canvas", 0, (Pixfont*) 0);
  1120. X    (void) panel_create_item(options_panel, PANEL_BUTTON,
  1121. X            PANEL_NOTIFY_PROC,    canvas_fit,
  1122. X            PANEL_LABEL_IMAGE,    pr,
  1123. X            0);
  1124. X    toggle_item = panel_create_item(options_panel, PANEL_TOGGLE,
  1125. X            PANEL_LAYOUT,        PANEL_HORIZONTAL,
  1126. X            PANEL_CHOICE_STRINGS,    "Label",
  1127. X                        "Square",
  1128. X                        "Reverse",
  1129. X                        (char *) 0,
  1130. X            PANEL_TOGGLE_VALUE,    LABEL, make_label,
  1131. X            PANEL_TOGGLE_VALUE,    SQUARE, square,
  1132. X            PANEL_TOGGLE_VALUE,    REVERSE, reverse,
  1133. X            PANEL_NOTIFY_PROC,    toggle_proc,
  1134. X            0);
  1135. X    font_item = panel_create_item(options_panel, PANEL_TEXT,
  1136. X            PANEL_VALUE_DISPLAY_LENGTH, 51,
  1137. X            PANEL_VALUE_STORED_LENGTH, MAX_NAME_LENGTH,
  1138. X            PANEL_LABEL_STRING,    "Font name:",
  1139. X            PANEL_VALUE,        font_name,
  1140. X            0);
  1141. X    hor_size_item = panel_create_item(options_panel, PANEL_SLIDER,
  1142. X            PANEL_LABEL_STRING,    "Horizontal size: ",
  1143. X            PANEL_VALUE,        hor_size,
  1144. X            PANEL_MIN_VALUE,    64,
  1145. X            PANEL_MAX_VALUE,    2048,
  1146. X            PANEL_SLIDER_WIDTH,    225,
  1147. X            0);
  1148. X    ver_size_item = panel_create_item(options_panel, PANEL_SLIDER,
  1149. X            PANEL_LABEL_STRING,    "Vertical size:   ",
  1150. X            PANEL_VALUE,        ver_size,
  1151. X            PANEL_MIN_VALUE,    64,
  1152. X            PANEL_MAX_VALUE,    2048,
  1153. X            PANEL_SLIDER_WIDTH,    225,
  1154. X            0);
  1155. X    window_fit(options_panel);
  1156. X    window_fit(options_frame);
  1157. X    if (square) {
  1158. X        panel_set(ver_size_item,
  1159. X            PANEL_SHOW_ITEM,    FALSE,
  1160. X            0);
  1161. X        panel_set(hor_size_item,
  1162. X            PANEL_LABEL_STRING,    "Canvas size:     ",
  1163. X            0);
  1164. X    }
  1165. X}
  1166. X
  1167. Xvoid panel_init()
  1168. X{
  1169. X    register Pixrect *pr;
  1170. X
  1171. X    panel = window_create(frame, PANEL, 0);
  1172. X    pr = panel_button_image(panel, "Next Page", 0, (Pixfont *) 0);
  1173. X    next_page_item = panel_create_item(panel, PANEL_BUTTON,
  1174. X            PANEL_NOTIFY_PROC,    nextpage,
  1175. X            PANEL_LABEL_IMAGE,    pr,
  1176. X            PANEL_SHOW_ITEM,    FALSE,
  1177. X            0);
  1178. X    pr = panel_button_image(panel, "Redraw", 0, (Pixfont *) 0);
  1179. X    (void) panel_create_item(panel, PANEL_BUTTON,
  1180. X            PANEL_NOTIFY_PROC,    redraw,
  1181. X            PANEL_LABEL_IMAGE,    pr,
  1182. X            0);
  1183. X    pr = panel_button_image(panel, "Zoom", 0, (Pixfont *) 0);
  1184. X    (void) panel_create_item(panel, PANEL_BUTTON,
  1185. X            PANEL_NOTIFY_PROC,    zoom,
  1186. X            PANEL_LABEL_IMAGE,    pr,
  1187. X            0);
  1188. X    pr = panel_button_image(panel, "Options", 0, (Pixfont *) 0);
  1189. X    (void) panel_create_item(panel, PANEL_BUTTON,
  1190. X            PANEL_NOTIFY_PROC,    options,
  1191. X            PANEL_LABEL_IMAGE,    pr,
  1192. X            0);
  1193. X    pr = panel_button_image(panel, "Dump", 0, (Pixfont *) 0);
  1194. X    (void) panel_create_item(panel, PANEL_BUTTON,
  1195. X            PANEL_NOTIFY_PROC,    dump,
  1196. X            PANEL_LABEL_IMAGE,    pr,
  1197. X            0);
  1198. X    pr = panel_button_image(panel, "Fit Screen", 0, (Pixfont *) 0);
  1199. X    (void) panel_create_item(panel, PANEL_BUTTON,
  1200. X            PANEL_NOTIFY_PROC,    fit_screen,
  1201. X            PANEL_LABEL_IMAGE,    pr,
  1202. X            0);
  1203. X    pr = panel_button_image(panel, "Quit", 0, (Pixfont *) 0);
  1204. X    (void) panel_create_item(panel, PANEL_BUTTON,
  1205. X            PANEL_NOTIFY_PROC,    quit,
  1206. X            PANEL_LABEL_IMAGE,    pr,
  1207. X            0);
  1208. X    window_fit_height(panel);
  1209. X}
  1210. X
  1211. Xcanvas_init()
  1212. X{
  1213. X    canvas = window_create(frame, CANVAS,
  1214. X            CANVAS_AUTO_SHRINK,    FALSE,
  1215. X            CANVAS_WIDTH,        hor_size,
  1216. X            CANVAS_HEIGHT,        ver_size,
  1217. X            CANVAS_RETAINED,    TRUE,
  1218. X            WIN_VERTICAL_SCROLLBAR,    scrollbar_create(0),
  1219. X            WIN_HORIZONTAL_SCROLLBAR, scrollbar_create(0),
  1220. X            0);
  1221. X    pw = canvas_pixwin(canvas);
  1222. X}
  1223. X
  1224. Xusage(cmd)
  1225. Xchar *cmd;
  1226. X{
  1227. X    fprintf(stderr, "\
  1228. X%s recognizes the following options:\n\
  1229. X\t-c canvas-size\t\t(set size of canvas)\n\
  1230. X\t-h horizontal-size\t(set horizontal size of canvas)\n\
  1231. X\t-v vertical-size\t(set vertical size of canvas)\n\
  1232. X\t-f font-name\t\t(use specified font for labels)\n\
  1233. X\t-r\t\t\t(rotate 90 degrees)\n\
  1234. X\t-x\t\t\t(mirror in x axis)\n\
  1235. X\t-y\t\t\t(mirror in y axis)\n\
  1236. X\t-l\t\t\t(don't print labels)\n\
  1237. X\t-s\t\t\t(don't force canvas to be square)\n\
  1238. X\t-R\t\t\t(display in reverse video)\n\
  1239. X", cmd);
  1240. X    exit(1);
  1241. X}
  1242. X
  1243. Xmain(argc, argv)
  1244. Xchar **argv;
  1245. X{
  1246. X    Cursor cursor;
  1247. X    register c;
  1248. X    extern char *optarg;
  1249. X
  1250. X    initplot();
  1251. X
  1252. X    hor_size = ver_size = INIT_CANVAS_SIZE;
  1253. X    frame = window_create(NULL, FRAME,
  1254. X            FRAME_LABEL,        "Sunplot",
  1255. X            FRAME_SUBWINDOWS_ADJUSTABLE, FALSE,
  1256. X            FRAME_ICON, icon_create(ICON_IMAGE, &sunplot_icon, 0),
  1257. X            FRAME_ARGC_PTR_ARGV,    &argc, argv,
  1258. X            0);
  1259. X    while ((c = getopt(argc, argv, "c:h:v:lsRrxyf:")) != EOF) {
  1260. X        switch (c) {
  1261. X        case 'c':
  1262. X            hor_size = atoi(optarg);
  1263. X            if (hor_size < 64)
  1264. X                hor_size = 64;
  1265. X            ver_size = hor_size;
  1266. X            square = TRUE;
  1267. X            break;
  1268. X        case 'h':
  1269. X            hor_size = atoi(optarg);
  1270. X            if (hor_size < 64)
  1271. X                hor_size = 64;
  1272. X            square = FALSE;
  1273. X            break;
  1274. X        case 'v':
  1275. X            ver_size = atoi(optarg);
  1276. X            if (ver_size < 64)
  1277. X                ver_size = 64;
  1278. X            square = FALSE;
  1279. X            break;
  1280. X        case 'l':
  1281. X            make_label = !make_label;
  1282. X            break;
  1283. X        case 's':
  1284. X            square = !square;
  1285. X            break;
  1286. X        case 'R':
  1287. X            reverse = !reverse;
  1288. X            break;
  1289. X        case 'r':
  1290. X            turn();
  1291. X            break;
  1292. X        case 'x':
  1293. X            mirrorx();
  1294. X            break;
  1295. X        case 'y':
  1296. X            mirrory();
  1297. X            break;
  1298. X        case 'f':
  1299. X            strcpy(font_name, optarg);
  1300. X            break;
  1301. X        default:
  1302. X            usage(argv[0]);
  1303. X            /*NOTREACHED*/
  1304. X        }
  1305. X    }
  1306. X    dump_init();
  1307. X    options_init();
  1308. X    panel_init();
  1309. X    canvas_init();
  1310. X    if (font_name[0]) {
  1311. X        register char *f = font_name;
  1312. X
  1313. X        if (*f != '/') {
  1314. X            f = malloc(strlen(font_dir)+strlen(font_name)+1);
  1315. X            strcpy(f, font_dir);
  1316. X            strcat(f, font_name);
  1317. X        }
  1318. X        font = pf_open(f);
  1319. X        if (f != font_name)
  1320. X            free(f);
  1321. X    }
  1322. X    if (font == 0) {
  1323. X        font = pf_default();
  1324. X        font_name[0] = 0;
  1325. X    }
  1326. X
  1327. X    fit_screen();
  1328. X
  1329. X    notify_set_input_func(me, input_reader, fileno(stdin));
  1330. X
  1331. X    linemod("solid");
  1332. X    restartplot();
  1333. X    cursor = (Cursor) window_get(canvas, WIN_CURSOR);
  1334. X    cursor_set(cursor,
  1335. X            CURSOR_OP, reverse ? PIX_SRC^PIX_DST : PIX_SRC|PIX_DST,
  1336. X            0);
  1337. X    window_set(canvas, WIN_CURSOR, cursor, 0);
  1338. X
  1339. X    window_main_loop(frame);
  1340. X
  1341. X    exit(0);
  1342. X}
  1343. END_OF_FILE
  1344. if test 22427 -ne `wc -c <'sunplot.c'`; then
  1345.     echo shar: \"'sunplot.c'\" unpacked with wrong size!
  1346. fi
  1347. # end of 'sunplot.c'
  1348. fi
  1349. if test -f 'sunplot.icon' -a "${1}" != "-c" ; then 
  1350.   echo shar: Will not clobber existing file \"'sunplot.icon'\"
  1351. else
  1352. echo shar: Extracting \"'sunplot.icon'\" \(1933 characters\)
  1353. sed "s/^X//" >'sunplot.icon' <<'END_OF_FILE'
  1354. X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
  1355. X */
  1356. X    0x0000,0x0000,0x0000,0x0400,0x0000,0x0000,0x0000,0x0400,
  1357. X    0x0000,0x0000,0x0000,0x0800,0x0000,0x0000,0x0000,0x0800,
  1358. X    0x0000,0x0000,0x0000,0x1000,0x0000,0x0000,0x7FF0,0x1000,
  1359. X    0x0000,0x0007,0x800F,0x1000,0x0000,0x0038,0x0000,0xE000,
  1360. X    0x0000,0x00C0,0x0000,0x3800,0x2000,0x0300,0x0000,0x4600,
  1361. X    0x1800,0x0400,0x0000,0x4100,0x07FF,0x0800,0x0000,0x8080,
  1362. X    0x03FF,0xFFFC,0x0000,0x8060,0x01C1,0xFFFF,0xFFF0,0x8010,
  1363. X    0x00E0,0x8037,0xFFFF,0xF008,0x0071,0x0030,0x001F,0xFE04,
  1364. X    0x003A,0x0030,0x0002,0x0002,0x001E,0x0060,0x0002,0x0002,
  1365. X    0x000F,0x0060,0x0002,0x0001,0x000F,0x8060,0x0004,0x0000,
  1366. X    0x0011,0xC0C0,0x0004,0x0000,0x0010,0xE0C0,0x0008,0x0000,
  1367. X    0x0020,0x7180,0x0008,0x0000,0x0020,0x3B80,0x0008,0x0000,
  1368. X    0x0040,0x1F00,0x0010,0x0000,0x0040,0x0E00,0x0010,0x0000,
  1369. X    0x0040,0x1F80,0x0020,0x0000,0x0080,0x3BC0,0x0020,0x0000,
  1370. X    0x0080,0x70E0,0x0040,0x0000,0x0081,0xE070,0x0040,0x0000,
  1371. X    0x0081,0xC038,0x0040,0x0000,0x0100,0x001C,0x0080,0x0000,
  1372. X    0x0100,0x000E,0x0080,0x0000,0x0100,0x0007,0x0100,0x0000,
  1373. X    0x0100,0x0003,0x8100,0x0000,0x0100,0x0001,0xE100,0x0000,
  1374. X    0x0100,0x0000,0xF200,0x0000,0x0100,0x0000,0x3A00,0x0000,
  1375. X    0x0100,0x0000,0x1C00,0x0000,0x0100,0x0000,0x0E00,0x0000,
  1376. X    0x0100,0x0000,0x0F00,0x0000,0x0100,0x0000,0x0B80,0x0000,
  1377. X    0x0080,0x0000,0x0980,0x0000,0x0080,0x0000,0x1040,0x0000,
  1378. X    0x0080,0x0000,0x1020,0x0000,0x0080,0x0000,0x2000,0x0000,
  1379. X    0x0040,0x0000,0x2000,0x0000,0x0040,0x0000,0x2000,0x0000,
  1380. X    0x0FFF,0xFFFF,0xFFFF,0xFFE0,0x0924,0x9249,0x2492,0x4920,
  1381. X    0x0924,0x9249,0x2492,0x4920,0x0924,0x9249,0x2492,0x4920,
  1382. X    0x0800,0x0000,0x0000,0x0020,0x0800,0x0000,0x0000,0x0020,
  1383. X    0x0800,0x0000,0x0000,0x0021,0x0800,0x0000,0x0000,0x0022,
  1384. X    0x0800,0x0000,0x0000,0x0022,0x0800,0x0000,0x0000,0x0024,
  1385. X    0x0FFF,0xFFFF,0xFFFF,0xFFE8,0x0000,0x4004,0x0000,0x0010,
  1386. X    0x0000,0x3008,0x0000,0x0060,0x0000,0x0808,0x0000,0x0080,
  1387. X    0x0000,0x0410,0x0000,0x0100,0x0000,0x0310,0x0000,0x0600
  1388. END_OF_FILE
  1389. if test 1933 -ne `wc -c <'sunplot.icon'`; then
  1390.     echo shar: \"'sunplot.icon'\" unpacked with wrong size!
  1391. fi
  1392. # end of 'sunplot.icon'
  1393. fi
  1394. echo shar: End of archive 1 \(of 1\).
  1395. cp /dev/null ark1isdone
  1396. MISSING=""
  1397. for I in 1 ; do
  1398.     if test ! -f ark${I}isdone ; then
  1399.     MISSING="${MISSING} ${I}"
  1400.     fi
  1401. done
  1402. if test "${MISSING}" = "" ; then
  1403.     echo You have the archive.
  1404.     rm -f ark[1-9]isdone
  1405. else
  1406.     echo You still need to unpack the following archives:
  1407.     echo "        " ${MISSING}
  1408. fi
  1409. ##  End of shell archive.
  1410. exit 0
  1411. -- 
  1412. Sjoerd Mullender        e-mail: sjoerd@cwi.nl
  1413. Centre for Mathematics and Computer Science, Amsterdam
  1414.  
  1415.